package com.joker.es.controller;


import com.joker.es.domain.EsResponse;
import com.joker.es.domain.SkuInfoEsModel;
import com.joker.es.query.SearchQuery;
import com.joker.es.result.SearchResult;
import com.joker.es.service.IEsService;
import com.joker.common.core.domain.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

import java.util.List;

/**
 * @author lemon
 * @date 2024/12/17 16:11
 **/
@RestController
@RequestMapping("/")
public class EsController{

    @Autowired
    private IEsService esService;

    @PostMapping("/addBatch")
    public Result<Boolean> addBatch(@RequestBody String data){
        return Result.success(esService.addBatch(data));
    }

    @GetMapping
    public Result<SearchResult> search(SearchQuery searchQuery){
        SearchResult searchResult = null;
        try {
            searchResult = esService.search(searchQuery);
        } catch (IOException e) {
            throw new RuntimeException("搜索失败");
        }
        return Result.success(searchResult);
    }

}
